/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.app;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import at.socialconference.app.twitter.TwitterHelper;
import at.socialconference.app.uihelper.AlertHelper;

public class TwitterSettingsActivity extends Activity implements OnClickListener {

	private Button btnOpenTwitter;
	private Button btnEnterPin;
	private EditText etPinField;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.twittersettingsview);
		
		btnOpenTwitter = (Button) findViewById(R.id.sv_getPin);
		btnEnterPin = (Button) findViewById(R.id.sv_enterPinBtn);
		etPinField = (EditText) findViewById(R.id.sv_pinField);
		
		btnOpenTwitter.setOnClickListener(this);
		btnEnterPin.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if(v.equals(btnOpenTwitter)){
			String url = TwitterHelper.getAuthURL();
			Intent i = new Intent(Intent.ACTION_VIEW);
			i.setData(Uri.parse(url));
			startActivity(i);
		}else if(v.equals(btnEnterPin)){
			String s = etPinField.getText().toString();
			int result = -1;
			if(s!=null && s.length()>0)
				result = TwitterHelper.setPin(s);
			if(result==1){
				AlertHelper.alert("Success","You can now user Twitter", true, this);
			}else{
				AlertHelper.alert("Failure","An Error appeared", false, this);
			}
				
		}
	}
}
